package com.clkj.zhonghui.dao.product;

import com.clkj.zhonghui.pojo.product.ProductAnswer;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;
import tk.mybatis.mapper.common.Mapper;
import tk.mybatis.mapper.common.MySqlMapper;

import java.util.List;
import java.util.Map;

/**
 * @Author：周佳润
 * @Date：2024/7/15 下午2:22
 */
@Repository
public interface ProductAnswerMapper extends Mapper<ProductAnswer>, MySqlMapper<ProductAnswer> {

    @Select("select b.*,a.answer_content as replyname  from t_zh_productAnswer a " +
            "JOIN t_zh_productAnswer b ON a.answer_id = b.parent_id  " +
            "where  b.parent_id != 0 " +
            "and b.product_id = #{productId} " +
            "order by answer_id desc")
    List<ProductAnswer> selectByAnswer(@Param("productId")Integer productId);

    @Select("<script>" +
            "select " +
            "<if test='flag==0'> top 1 </if>" +
            " * from t_zh_productAnswer where parent_id =0 and answer_status =1  and product_id=  #{productId} order by answer_id desc " +
            "</script>")
    List<ProductAnswer> listAnswer(Integer productId,Integer flag);

    @Select("select t.*,u.user_name AS userName, u.user_img AS userImg from  t_zh_productAnswer AS t JOIN t_zh_user AS u ON t.user_id = u.user_id where t.product_id = #{productId} and t.parent_id = 0 and t.answer_status = 1 " +
            "order by answer_date desc")
    List<ProductAnswer> selectProductAnswer(@Param("productId")Integer productId);

    @Select("select t.* ,u.user_name AS userName, u.user_img AS userImg " +
            "from  t_zh_productAnswer AS t JOIN t_zh_user AS u ON t.user_id = u.user_id where t.parent_id = #{answerId}  and t.answer_status = 1 " +
            "order by answer_date desc")
    List<ProductAnswer> selectAnswerList(int answerId);
}
